<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Dao;

use App\Traits\DaoTrait;
use Hyperf\Context\Context;
use Hyperf\DbConnection\Model\Model;

/**
 * 数据访问层
 * Class AbstractDao.
 */
abstract class AbstractDao
{
    /**
     * utils.
     */
    use DaoTrait;

    public $model;

    public array $searchFields = [];

    public function __construct()
    {
        $this->assignModel();
    }

    abstract public function assignModel();

    public function getModel(): Model
    {
        return new $this->model();
    }

    /**
     * 把数据设置为类属性.
     * @param array $data
     */
    public static function setAttributes(array $data): void
    {
        Context::set('attributes', $data);
    }

    /**
     * 获取数据.
     */
    public function getAttributes(): array
    {
        return Context::get('attributes', []);
    }
}
